**# Bookmark #1 Setting

*Windows
global root  = "G:/Dropbox/Environmental Injustice/Empirical"
global rawdata = "$root/rawdata"
global workdata = "$root/workdata"
global results = "$root/results"
global outfile = "$root/outfile"

cd "$workdata"


**# Bookmark #2 Table 1 Panel A: Below College
use "$outfile/City_regression.dta",clear

reghdfe codemission c.belowcl##i.post cityranking,absorb(i.province) cluster(i.province i.year)

outreg2 using "$results/Table1.xls",replace ctitle("COD Emission") ///
keep(1.post#c.belowcl belowcl 1.post) ///
addtext(Province FE, YES, City FE, NO, Firm FE, NO, ProvincebyYear FE, NO) ///
bdec(3) tdec(3) rdec(3)


reghdfe codemission c.belowcl##i.post,absorb(i.city i.province#i.year) cluster(i.province i.year)

outreg2 using "$results/Table1.xls",append ctitle("COD Emission") ///
keep(1.post#c.belowcl belowcl 1.post) ///
addtext(Province FE, NO, City FE, YES, Firm FE, NO, ProvincebyYear FE, YES) ///
bdec(3) tdec(3) rdec(3)


*Firm-level COD Emission
use "$outfile/Firm_regression.dta",clear

reghdfe codemission c.belowcl##i.post,absorb(i.id i.province#i.year) cluster(i.province i.year)

outreg2 using "$results/Table1.xls",append ctitle("COD Emission") ///
keep(1.post#c.belowcl belowcl 1.post) ///
addtext(Province FE, NO, City FE, NO, Firm FE, YES, ProvincebyYear FE, YES) ///
bdec(3) tdec(3) rdec(3)


*Firm Entry
use "$outfile/Firm_entry_regression.dta",clear

reghdfe entrynum c.belowcl##i.post,absorb(i.city i.province#i.year) cluster(i.province i.year)

outreg2 using "$results/Table1.xls",append ctitle("Firm Entry") ///
keep(1.post#c.belowcl belowcl 1.post) ///
addtext(Province FE, NO, City FE, YES, Firm FE, NO, ProvincebyYear FE, YES) ///
bdec(3) tdec(3) rdec(3)

*Firm Exit
use "$outfile/Firm_exit_regression.dta",clear

reghdfe exitnum c.belowcl##i.post,absorb(i.city i.province#i.year) cluster(i.province i.year)

outreg2 using "$results/Table1.xls",append ctitle("Firm Exit") ///
keep(1.post#c.belowcl belowcl 1.post) ///
addtext(Province FE, NO, City FE, YES, Firm FE, NO, ProvincebyYear FE, YES) ///
bdec(3) tdec(3) rdec(3)

**# Bookmark #3 Table 1 Panel B: Below HS
*City-level COD Emission
use "$outfile/City_regression.dta",clear
	
reghdfe codemission c.belowhs##i.post cityranking,absorb(i.province) cluster(i.province i.year)

outreg2 using "$results/Table1.xls",append ctitle("COD Emission") ///
keep(1.post#c.belowhs belowhs 1.post) ///
addtext(Province FE, YES, City FE, NO, Firm FE, NO, ProvincebyYear FE, NO) ///
bdec(3) tdec(3) rdec(3)


reghdfe codemission c.belowhs##i.post,absorb(i.city i.province#i.year) cluster(i.province i.year)

outreg2 using "$results/Table1.xls",append ctitle("COD Emission") ///
keep(1.post#c.belowhs belowhs 1.post) ///
addtext(Province FE, NO, City FE, YES, Firm FE, NO, ProvincebyYear FE, YES) ///
bdec(3) tdec(3) rdec(3)


*Firm-level COD Emission
use "$outfile/Firm_regression.dta",clear

reghdfe codemission c.belowhs##i.post,absorb(i.id i.province#i.year) cluster(i.province i.year)

outreg2 using "$results/Table1.xls",append ctitle("COD Emission") ///
keep(1.post#c.belowhs belowhs 1.post) ///
addtext(Province FE, NO, City FE, NO, Firm FE, YES, ProvincebyYear FE, YES) ///
bdec(3) tdec(3) rdec(3)


*Firm Entry
use "$outfile/Firm_entry_regression.dta",clear

reghdfe entrynum c.belowhs##i.post,absorb(i.city i.province#i.year) cluster(i.province i.year)

outreg2 using "$results/Table1.xls",append ctitle("Firm Entry") ///
keep(1.post#c.belowhs belowhs 1.post) ///
addtext(Province FE, NO, City FE, YES, Firm FE, NO, ProvincebyYear FE, YES) ///
bdec(3) tdec(3) rdec(3)

*Firm Exit
use "$outfile/Firm_exit_regression.dta",clear

reghdfe exitnum c.belowhs##i.post,absorb(i.city i.province#i.year) cluster(i.province i.year)

outreg2 using "$results/Table1.xls",append ctitle("Firm Exit") ///
keep(1.post#c.belowhs belowhs 1.post) ///
addtext(Province FE, NO, City FE, YES, Firm FE, NO, ProvincebyYear FE, YES) ///
bdec(3) tdec(3) rdec(3)


**# Bookmark #4 Table 1 Panel C: Summary Statistica
clear
matrix T = J(6, 5, .)

*Column 1 and 2
use "$outfile/City_regression.dta",clear

reghdfe codemission c.belowcl##i.post,absorb(i.city i.province#i.year) cluster(i.province i.year)
keep if e(sample)==1

sum codemission if post==0
local preymean= r(mean)
sum codemission if post==1
local postymean= r(mean)

sum belowhs
local meanbelowhs= r(mean)
local sdbelowhs= r(sd)

sum belowcl
local meanbelowcl= r(mean)
local sdbelowcl= r(sd)

matrix T[1,1] = `preymean'
matrix T[2,1] = `postymean'
matrix T[3,1] = `meanbelowcl'
matrix T[4,1] = `sdbelowcl'
matrix T[5,1] = `meanbelowhs'
matrix T[6,1] = `sdbelowhs'

matrix T[1,2] = `preymean'
matrix T[2,2] = `postymean'
matrix T[3,2] = `meanbelowcl'
matrix T[4,2] = `sdbelowcl'
matrix T[5,2] = `meanbelowhs'
matrix T[6,2] = `sdbelowhs'

*Column 3
use "$outfile/Firm_regression.dta",clear

reghdfe codemission c.belowhs##i.post,absorb(i.id i.province#i.year) cluster(i.province i.year)
keep if e(sample)==1

sum codemission if post==0
local preymean= r(mean)
sum codemission if post==1
local postymean= r(mean)

matrix T[1,3] = `preymean'
matrix T[2,3] = `postymean'
matrix T[3,3] = `meanbelowcl'
matrix T[4,3] = `sdbelowcl'
matrix T[5,3] = `meanbelowhs'
matrix T[6,3] = `sdbelowhs'


*Column 4
use "$outfile/Firm_entry_regression.dta",clear

reghdfe entrynum c.belowhs##i.post,absorb(i.city i.province#i.year) cluster(i.province i.year)
keep if e(sample)==1

sum entrynum if post==0
local preymean= r(mean)
sum entrynum if post==1
local postymean= r(mean)

matrix T[1,4] = `preymean'
matrix T[2,4] = `postymean'
matrix T[3,4] = `meanbelowcl'
matrix T[4,4] = `sdbelowcl'
matrix T[5,4] = `meanbelowhs'
matrix T[6,4] = `sdbelowhs'


*Column 5
use "$outfile/Firm_exit_regression.dta",clear

reghdfe exitnum c.belowhs##i.post,absorb(i.city i.province#i.year) cluster(i.province i.year)
keep if e(sample)==1

sum exitnum if post==0
local preymean= r(mean)
sum exitnum if post==1
local postymean= r(mean)

matrix T[1,5] = `preymean'
matrix T[2,5] = `postymean'
matrix T[3,5] = `meanbelowcl'
matrix T[4,5] = `sdbelowcl'
matrix T[5,5] = `meanbelowhs'
matrix T[6,5] = `sdbelowhs'

*Combine
matrix list T
svmat T, names(col)
keep c1 c2 c3 c4 c5
drop if c1==.
format c1 c2 c3 c4 c5 %9.3f

gen colname = ""
replace colname = "Pre-period Mean of Dep. Var." in 1
replace colname = "Post-period Mean of Dep. Var." in 2
replace colname = "Mean of Share of Below College" in 3
replace colname = "SD of Share of Below College" in 4
replace colname = "Mean of Share of Below HS" in 5
replace colname = "SD of Share of Below HS" in 6
